#ifndef DBUSARGVITEM_HPP
#define DBUSARGVITEM_HPP

#include <QObject>
#include <QList>
#include <QVariant>
#include <qvalidator.h>
#include "common.hpp"
#define DBUS_TYPE_STRUCT QMetaType::User+2001
#define DBUS_TYPE_DICT   QMetaType::User+2002
#define DBUS_TYPE_ARRAR  QMetaType::User+2003
#define DBUS_TYPE_DICT_KEY   QMetaType::User+2004
#define DBUS_TYPE_DICT_Value   QMetaType::User+2005
#define LEVEL_ROOT 0
#define LEVEL_TOP 1


class DBusArgvItem : public QObject
{
    Q_OBJECT

public:


    explicit DBusArgvItem(const QStringList &name, const QStringList &DBusArgs);
    explicit DBusArgvItem(const QStringList &name, const QList<int> &DBusArgs);
    DBusArgvItem(const QStringList &name, const QList<DVariant> values);
    DBusArgvItem(const QString &name, const int &DBusArgs, DBusArgvItem *parent);
    DBusArgvItem(const QString &name, const QString &DBusArgs, DBusArgvItem *parent);
    DBusArgvItem(const QString &name, const DVariant &value, DBusArgvItem *parent);
    DBusArgvItem(const QString &name, const QString &keyArgs,const QString &DBusArgs, DBusArgvItem *parent);
    DBusArgvItem(const QString &name, const QString &DBusArgs, DBusArgvItem *parent,int parenttype);
    DBusArgvItem(const QString &name, const DVariant &value, DBusArgvItem *parent,int parenttype);
    DBusArgvItem(DBusArgvItem *parent,int parenttype);
    QList<DVariant> getArgs(bool *ok);
    inline QString lastError(){return m_lastError;}
    DVariant getArg(bool *ok);
    //    DBusArgvItem(const QString &name, const QString &keyArgs, const QString &ValueArgs,DBusArgvItem *parent);
    ~DBusArgvItem();
    void print();
    DBusArgvItem *child(int number);
    int childCount() const;
    int columnCount() const;
    QVariant data(int column);
    DBusArgvItem *parent();
    int childNumber() const;
    bool setValue(const QVariant &value);
    bool setKey(const QVariant &value);
    bool buildItem();
    bool buildItem(const DVariant value);
    bool insertSubItem();
    int addChild(DBusArgvItem *item);
    QString getArraySubArgType();
    QString getDictKeyArgType();
    QString getDictValueArgType();

    int adjustItem(int &addRowfrom,int &addRowto);

    QVariant getName() const;
    //    QVariant getKey() const;
    QVariant getValue() const;

    int getParenttype() const;

    QString getTypeName() const;

    int getKeyType() const;

    int getValueType() const;

    //    QString getKeysDBusArgs() const;

    QString getValueDBusArgs() const;

    DBusArgvItem *getParentItem() const;

    int getLevel() const;
    void setLevel(int level);

    QList<DBusArgvItem *> getChildItems() const;

signals:

public slots:
public:
    bool getTypes(QString DBusArgs,int &type,QString &typeName,QValidator **validator);
    bool getDictType(QString DBusArgs,QString &key,QString &Value,QString &out);
    QList<DBusArgvItem*> childItems;
    QString m_Name;
    QString m_TypeName;
    QStringList m_subTypes;
    QString m_ValueDBusArgs;
    int m_ValueType;
    QVariant m_value;
    int m_parenttype;
    QString m_lastError;
    ShowModel m_showModel;
    DBusArgvItem *parentItem;
    int m_level;
    int getItemType(const QString &DBusArgs);
    int getNextType(QString DBusArgs, QString &Value, QString &out);
    QString getTypeNameFromType(int type);
};

#endif // DBUSARGVITEM_HPP
